package com.melon.modules.exception.web;

import com.melon.modules.exception.entity.MyException;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/demo/exception")
public class ExceptionDemoController {


    /**
     * 0异常
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = {"/demo01"})
    public Object demo01(HttpServletRequest request) {
        int i = 1 / 0;
        return "exception demo01";
    }

    /**
     * 自定义异常
     *
     * @return
     * @throws MyException
     */
    @RequestMapping("/myexception")
    public String json() throws MyException {
        throw new MyException("发生错误2");
    }

    /***
     * 参数异常测试
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/demo02")
    public String demo02(@RequestParam("id") String id) {

        return "demo02";
    }


}
